﻿#region Vương văn hùng
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data.SqlClient;
using System.Data;
using System.Collections;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;

using DataAccess;
using Entities;
using Common;

namespace BusinessLogic
{
    public static class GetCombobox
    {
        public static Entities.GetCombobox[] SelectCombox(Entities.GetCombobox combox)
        {
            Entities.GetCombobox[] list = null;
            try
            {
                //lay mo ket noi voi' chuoi~ ket noi lay' tu` file app.confg trong GUI
                SqlConnection cn = DataAccess.Connection.OpenConnection();
                SqlCommand cmd = new SqlCommand(Common.Constants.LayCombox.sp_LayCombox, cn);
                cmd.Parameters.Add(Common.Constants.LayCombox.tableName, SqlDbType.NVarChar,20).Value = combox.TenBang;
                cmd.Parameters.Add(Common.Constants.LayCombox.columnID, SqlDbType.NVarChar,20).Value = combox.TenCotKhoaChinh;
                cmd.Parameters.Add(Common.Constants.LayCombox.columnName, SqlDbType.NVarChar,20).Value = combox.TenCotTenHienThi;
                SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                ArrayList arr = new ArrayList();
                while (dr.Read())
                {
                    Entities.GetCombobox row = new Entities.GetCombobox();
                    row.TenCotKhoaChinh = dr[0].ToString();
                    row.TenCotTenHienThi = dr[1].ToString();
                    arr.Add(row);
                }
                int n = arr.Count;
                if (n == 0) { list = null; }
                list = new Entities.GetCombobox[n];
                for (int i = 0; i < n; i++)
                {
                    list[i] = (Entities.GetCombobox)arr[i];
                }
                cmd.Connection.Dispose();
                cn.Close();
                DataAccess.Connection.CloseConnection();
            }
            catch (Exception ex)
            { 
                string s = ex.Message.ToString(); 
                list = null; 
            }
            return list;
        }
    }
}
#endregion
